package dominioDAO;

import hbt.HibernateDAO;
import hbt.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;



// Cliente lado Servidor DAO (Persistencia)

public class RemitoClienteDAO{
	private static RemitoClienteDAO instancia ;
	private static SessionFactory sf;
	private static Session session;
	
	public static RemitoClienteDAO getInstancia() {
		if(instancia == null){
			instancia = new RemitoClienteDAO();
		} 
		return instancia;
	}
	public RemitoClienteDAO()
	{
		sf = HibernateUtil.getSessionFactory();
	}
	
	protected Session getSession(){
		if(session == null || !session.isOpen()){
			session = sf.openSession();
		}
		return session;
	}
	
	protected void closeSession()
	{
		if(session.isOpen())
		{
			session.close();
		}
	}
	

	public Integer getNroRemito()
	{
		String query = "select MAX(r.numeroRemitoCliente) from RemitoCliente r";
		Integer i = (Integer)HibernateDAO.getInstancia().totalizador(query);
		if(i==null)
		{
			return 1;
		}
		return i+1;
	}
	


}
